package com.wuwei.controller;


import com.wuwei.pojo.CommonResult;
import com.wuwei.pojo.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @description: PaymentController <br>
 * @date: 2021/2/21 23:32 <br>
 * @author: wuwei666 <br>
 * @version: 1.0 <br>
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private Integer port;

    private static Map<Long, Payment> hashMap = new HashMap<>();

    static {
        hashMap.put(1L, new Payment(1L, UUID.randomUUID().toString()));
        hashMap.put(2L, new Payment(2L, UUID.randomUUID().toString()));
        hashMap.put(3L, new Payment(3L, UUID.randomUUID().toString()));
    }

    @GetMapping("/provider/{id}")
    public CommonResult<Payment> payment(@PathVariable("id") Long id){
        Payment payment = hashMap.get(id);
        CommonResult<Payment> paymentCommonResult = new CommonResult<Payment>(200, "serverPort:" + port, payment);
        return paymentCommonResult;
    }
}
